package com.dhnsoft.boot.core.controller;

import com.dhnsoft.boot.core.entity.User;
import com.dhnsoft.boot.core.event.EventPublisher;
import com.dhnsoft.boot.core.event.LoginSuccessEvent;
import com.dhnsoft.boot.core.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author dhn
 * @version 1.0
 * @date 2023-09-05 17:25
 * @Desc
 */
@RestController
public class LoginController {

    @Autowired
    private AccountService accountService;

    @Autowired
    private EventPublisher eventPublisher;

    @GetMapping("/login")
    public String login(@RequestParam("username") String username,@RequestParam("password")String password){
        //业务处理登录
        System.out.println("业务处理登录完成....");
        User user = new User(username, password);
        //TODO 发送事件
        LoginSuccessEvent loginSuccessEvent = new LoginSuccessEvent(user);
        eventPublisher.sendEvent(loginSuccessEvent);

        //账户服务自动签到加积分
//        accountService.addAccountService(username);

        //设计模式：对新增开发，对修改关闭
        return username+"登录成功";
    }
}
